//
//  ST_RegisterInvitationCodeViewController.swift
//  btvideo
//
//  Created by Jason on 2021/9/28.
//  Copyright © 2021 JarvanZhang. All rights reserved.
//

import UIKit
import SwifterSwift
import SnapKit
import HandyJSON
import RxCocoa
import RxSwift
import SwiftyAttributes

//邀请码
class ST_RegisterInvitationCodeViewController: UIViewController,ST_RegisterRouteProtocol {

    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.backgroundColor = .white
        
        view.addSubview(progress_view)
        progress_view.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalToSuperview().offset(statusBarHeight + 25)
            make.height.equalTo(2)
        }
        
        view.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(progress_view.snp.bottom).offset(26)
            make.height.equalTo(24)
        }
        
        view.addSubview(sub_title_label)
        sub_title_label.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(titleLabel.snp.bottom).offset(4)
            make.height.equalTo(20)
        }
        
        view.addSubview(textRootView)
        textRootView.snp.makeConstraints { make in
            make.width.equalTo(300)
            make.height.equalTo(60)
            make.centerX.equalToSuperview()
            make.top.equalTo(sub_title_label.snp.bottom).offset(69)
        }
        
        textRootView.addSubview(textFiled)
        textFiled.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.init(top: 0, left: 20, bottom: 0, right: 15))
        }
        
        view.addSubview(start_btn)
        start_btn.snp.makeConstraints { (make) in
            make.bottom.equalToSuperview().offset(-BTSafeAreaBottom-46)
            make.centerX.equalToSuperview()
            make.width.equalTo(260)
            make.height.equalTo(40)
        }
        
        
    }
    

//    MARK: - properties
    fileprivate lazy var progress_view: registerProgressView = {
        let v = registerProgressView()
//        v.setProgress(all: 6, p: 1)
        return v
    }()
    
    fileprivate lazy var titleLabel:UILabel = {
        let control = UILabel.init()
        control.text = "请输入你的邀请码"
        control.textColor = Color.init(hexString: "#333333")
        control.numberOfLines = 0
        control.textAlignment = .center
        control.font = UIFont.systemFont(ofSize: 17, weight: UIFont.Weight.medium)
        return control
    }()
    
    fileprivate lazy var sub_title_label: UILabel = {
        let l = UILabel()
        l.text = "如果没有可不填，直接下一步跳过"
        l.textColor = Color.init(hexString: "#999999")
        l.font = .systemFont(ofSize: 14, weight: .regular)
        l.textAlignment = .center
        return l
    }()
    
    fileprivate lazy var textRootView:UIView = {
        let l = UIView()
        l.backgroundColor = #colorLiteral(red: 0.9490196078, green: 0.9490196078, blue: 0.9490196078, alpha: 1)
        l.cornerRadius = 30
        return l
    }()

    fileprivate lazy var textFiled:UITextField = {
        let control = UITextField()
        control.textColor = UIColor.init(hex: 0x333333)
        control.font = UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.regular)
        control.tintColor = UIColor.init(hex: 0x333333)
        control.clearButtonMode = .whileEditing
        control.textAlignment = .center
        if let pas = UIPasteboard.general.string,pas.isAlphabetic && pas.count == 6{
            control.text = pas
        }else{
            control.attributedPlaceholder = "可不填".withAttributes([.font(.systemFont(ofSize: 16, weight: .regular)),.textColor(#colorLiteral(red: 0.6, green: 0.6, blue: 0.6, alpha: 1))])
        }
        return control
    }()
    
    fileprivate lazy var start_btn:UIButton = {
       
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        
        control.cornerRadius = 20

        
        control.setBackgroundImage(UIImage.init(color: UIColor.init(hex: 0xFEC207)!, size: CGSize.init(width: 1, height: 1)), for: UIControl.State.normal)
        
        control.setBackgroundImage(UIImage.init(color: UIColor.init(hex: 0xDFE3E9)!, size: CGSize.init(width: 1, height: 1)), for: UIControl.State.disabled)
        
        control.setTitleForAllStates("下一步")
        
        control.setTitleColorForAllStates(UIColor.white)
        
        control.setTitleColor(UIColor.white, for: UIControl.State.disabled)
        
        control.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.semibold)
        
        control.addTarget(self, action: #selector(start_action), for: UIControl.Event.touchUpInside)
        
        return control
    }()
    
}
//MARK: - Event
extension ST_RegisterInvitationCodeViewController{
    
    @objc func start_action(){
        
        if let text = textFiled.text,text.isAlphabetic,text.count == 6{
            pushNextRegisterController(parameters: ["invitation_code":text])
        }else{
            pushNextRegisterController(parameters: nil)
        }
    }
    
}
